package com.txunda.zhuohired.adapter.user.resume;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.bean.user.resume.JobHistoryBean;

import java.util.List;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/3/7 10:36
 * 功能描述：工作/实习经历adapter
 * 联系方式：jiahuanchen@126.com
 */

public class JobHistoryAdapter extends BaseAdapter {
    private Context context;
    private ViewHolder holder;
    private int historyStatus;
    private List<JobHistoryBean.DataBean> jobHistoryList;
    /**
     * 自定义监听
     */
    private HolderClickListener mHolderClickListener;

    public JobHistoryAdapter(Context context, int historyStatus, List<JobHistoryBean.DataBean> jobHistoryList) {
        this.context = context;
        this.historyStatus = historyStatus;
        this.jobHistoryList = jobHistoryList;
    }

    @Override
    public int getCount() {
        return jobHistoryList.size();
    }

    @Override
    public Object getItem(int i) {
        return jobHistoryList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_job_history, null);
            holder = new ViewHolder();
            view.setTag(holder);
            ViewUtils.inject(holder, view);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        if (historyStatus == 1) {
            holder.iv_item_job_history_delete.setVisibility(View.GONE);
        } else {
            holder.iv_item_job_history_delete.setVisibility(View.VISIBLE);
            holder.iv_item_job_history_delete.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    mHolderClickListener.onSureHolderClick(i);
                }
            });
        }
        if (TextUtils.isEmpty(jobHistoryList.get(i).getTime())) {
            holder.tv_item_job_history_time.setVisibility(View.GONE);
        } else {
            holder.tv_item_job_history_time.setVisibility(View.VISIBLE);
            holder.tv_item_job_history_time.setText(jobHistoryList.get(i).getTime());
        }
        if (TextUtils.isEmpty(jobHistoryList.get(i).getCompany_name())) {
            holder.tv_item_job_history_company.setVisibility(View.GONE);
        } else {
            holder.tv_item_job_history_company.setVisibility(View.VISIBLE);
            holder.tv_item_job_history_company.setText(jobHistoryList.get(i).getCompany_name());
        }
        if (TextUtils.isEmpty(jobHistoryList.get(i).getPosition_name())) {
            holder.tv_item_job_history_post.setVisibility(View.GONE);
        } else {
            holder.tv_item_job_history_post.setVisibility(View.VISIBLE);
            holder.tv_item_job_history_post.setText(jobHistoryList.get(i).getPosition_name());
        }
        return view;
    }

    class ViewHolder {
        /**
         * 删除
         */
        @ViewInject(R.id.iv_item_job_history_delete)
        private ImageView iv_item_job_history_delete;
        /**
         * 工作时间
         */
        @ViewInject(R.id.tv_item_job_history_time)
        private TextView tv_item_job_history_time;
        /**
         * 公司名称
         */
        @ViewInject(R.id.tv_item_job_history_company)
        private TextView tv_item_job_history_company;
        /**
         * 岗位名称
         */
        @ViewInject(R.id.tv_item_job_history_post)
        private TextView tv_item_job_history_post;
    }
    /**
     * 自定义监听
     *
     * @param holderClickListener
     */
    public void SetOnClickListener(HolderClickListener holderClickListener) {
        this.mHolderClickListener = holderClickListener;
    }

    /**
     * 自定义监听
     */
    public interface HolderClickListener {
        void onSureHolderClick(int position);

    }
}
